package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjCodeUserRegisterFieldValOption;
import com.zb.mapper.ZjCodeUserRegisterFieldValOptionMapper;
import com.zb.service.ZjCodeUserRegisterFieldValOptionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 编码用户登记字段选项值表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-01-02
 */
@Service
public class ZjCodeUserRegisterFieldValOptionServiceImpl extends ServiceImpl<ZjCodeUserRegisterFieldValOptionMapper, ZjCodeUserRegisterFieldValOption> implements ZjCodeUserRegisterFieldValOptionService {

    // 根据[编码用户登记表ID]删除字段选项值
    @Override
    public void deleteByCodeUserRegisterId(Long codeUserRegisterId) {
        QueryWrapper<ZjCodeUserRegisterFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.eq("code_user_register_id", codeUserRegisterId);
        this.remove(wrapper);
    }

    // 根据[编码用户登记字段值表ID]集合查询
    @Override
    public List<ZjCodeUserRegisterFieldValOption> getByCodeUserRegisterFieldValIds(List<Long> codeUserRegisterFieldValIds) {
        if (CollectionUtil.isEmpty(codeUserRegisterFieldValIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjCodeUserRegisterFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.select("id", "code_user_register_id",  "code_user_register_field_val_id", "opt_value");
        wrapper.in("code_user_register_field_val_id", codeUserRegisterFieldValIds);
        return this.list(wrapper);
    }
}
